import {createStore} from 'vuex'

let store=createStore({
  state(){//公共状态
    return {
      cartNum:1
    }
  },
  mutations:{ //同步修改state数据的方法
     changeCart(state,num){
        state.cartNum=num;
     }
  },
  actions:{ //异步修改state的数据
    cartAction({commit},num){
        commit('changeCart',num)
    }
  },
  getters:{
    cartDou(state){
      return state.cartNum*2
    }
  },
  modules:{}
})
export default store
